<?php
$id = $_REQUEST["id"];
$tblname = $_REQUEST["tblname"];
?>

<script type="text/javascript">
    $(document).ready(function() {
        $("#cancel_date").datepicker({
            dateFormat: "yy-mm-dd"
        });

        $("input,select,textarea").not("[type=submit]").jqBootstrapValidation({
            submitSuccess: function($form, event) {
                event.preventDefault();
                //alert("success");

                var tblname = $("#tblname").val();

                switch (tblname) {
                    case "tbl_promise_budget":
                        var file_process = "promise_budget_process.php";
                        var pages = "v_promise_budget";
                        break;

                    case "tbl_pet_budget":
                        var file_process = "budget_process.php";
                        var pages = "v_budget";
                        break;



                    case "tbl_promise_borrow":
                        var file_process = "promise_borrow_process.php";
                        var pages = "promise_borrow_view";
                        break;

                    case "tbl_pet_borrow":
                        var file_process = "pet_borrow_process.php";
                        var pages = "pet_borrow_view";
                        break;

                }
                //alert(tblname);
                $.ajax({
                    type: "POST",
                    url: file_process,
                    data: $('#frm_main').serialize(),
                    cach: false,
                    error: function() {
                        alert("ERROR !!!!");
                    },
                    success: function(data) {
                        //alert(data);
                        window.location.href = "index.php?pages=" + pages;

                    }
                });
            }
        });
    });
</script>
<form method="post" id="frm_main" name="frm_main" novalidate>
    <div class="control-group">
        <label>วันที่</label>
        <div class="controls">
            <input type="text" id="cancel_date" name="cancel_date" required>
        </div>
    </div>
    <div class="control-group">
        <label>เหตุผล</label>
        <div class="controls">
            <textarea class="input-block-level" rows="7" name="cancel_reason" id="cancel_reason" required></textarea>
        </div>
    </div>

    <div class="form-actions">
        <input type="hidden" id="id" name="id" value="<?php echo $id; ?>">
        <input type="hidden" id="tblname" name="tblname" value="<?php echo $tblname; ?>">
        <input type="hidden" id="task" name="task" value="cancel">

        <button type="submit" class="btn btn-info" id="save_changes" >บันทึกข้อมูล</button>
        <!--<input type="submit" class="btn btn-info" value="บันทึกข้อมูล">-->
        <a class="btn close-dialog"><i class="icon-remove"></i> ยกเลิก</a>

    </div>
</form>